<!--
 * @Author: yaonan
 * @Date: 2021-10-25 16:03:12
 * @LastEditors: yaonan
 * @LastEditTime: 2021-11-08 09:57:29
 * @Description:实名认证
-->
<template>
  <div class>
    <!-- 第一行开始-->
    <div>
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <!-- 时间日期 -->
        <el-date-picker
          v-model="searchForm.time"
          value-format="timestamp"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
        >
        </el-date-picker>
        <!-- 模糊查询 -->
        <el-form-item>
          <el-select
            v-model="searchForm.status"
            style="margin-left: 10px"
            placeholder="请选择状态"
            clearable
          >
            <el-option label="通过" value="通过"></el-option>
            <el-option label="不通过" value="不通过"></el-option>
            <el-option label="未审核" value="未审核"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="searchForm.user"
            style="margin-left: 10px"
            placeholder="申请人编号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch" style="margin-left: 10px"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 第一行结束-->
    <!-- 表格开始 -->
    <div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" :index="1" label="序号" width="60px">
        </el-table-column>
        <el-table-column prop="userId" label="申请人编号" width="120">
        </el-table-column>
        <el-table-column prop="realname" label="姓名" width="110">
        </el-table-column>
        <el-table-column
          prop="applyTime"
          label="申请时间"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            {{ moment(scope.row.applyTime).format("YYYY-MM-DD :HH:MM:ss") }}
          </template>
        </el-table-column>
        <el-table-column
          prop="idCard"
          label="身份证号"
          width="160px"
          align="center"
        >
        </el-table-column>
        <el-table-column label="身份证正面">
          <template slot-scope="scope">
            <el-popover placement="right-start" trigger="hover">
              <el-image
                slot="reference"
                :src="scope.row.idcardPhotoPositive"
                style="width: 30px; height: 30px"
                fit="contain"
              ></el-image>
              <el-image
                :src="scope.row.idcardPhotoPositive"
                style="width: 200px; height: 200px"
                fit="contain"
              ></el-image>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="idcardPhotoNegative" label="身份证反面">
          <template slot-scope="scope">
            <el-popover placement="right-start" trigger="hover">
              <el-image
                slot="reference"
                :src="scope.row.idcardPhotoNegative"
                style="width: 30px; height: 30px"
                fit="contain"
              ></el-image>
              <el-image
                :src="scope.row.idcardPhotoNegative"
                style="width: 200px; height: 200px"
                fit="contain"
              ></el-image>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="bankCard" label="银行卡号" width="150">
        </el-table-column>
        <el-table-column label="银行卡">
          <template slot-scope="scope">
            <el-popover placement="right-start" trigger="hover">
              <el-image
                slot="reference"
                :src="scope.row.bankCardPhoto"
                style="width: 30px; height: 30px"
                fit="contain"
              ></el-image>
              <el-image
                :src="scope.row.bankCardPhoto"
                style="width: 200px; height: 200px"
                fit="contain"
              ></el-image>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.status === '通过'">{{
              scope.row.status
            }}</el-tag>
            <el-tag type="danger" v-else>{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              @click="changeStatus(scope.row.id, '通过')"
              v-if="scope.row.status === '未审核'"
              type="text"
              size="small"
              >通过</el-button
            >
            <el-button
              @click="changeStatus(scope.row.id, '不通过')"
              v-if="scope.row.status === '未审核'"
              type="text"
              size="small"
              >不通过</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 表格结束 -->
    <!-- 分页 -->
    <div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.page"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
let moment = require("moment");
import {
  pageQueryCertificationApply,
  checkPass,
  checkNoPass,
  revokeCertificationApply,
  submitCertificationApply,
} from "@/api/authentication";
export default {
  // 组件名称
  name:'demo',
  // 组件参数 接收来自父组件的数据
  props:{},
  // 组件状态值
  data() {
    return {
      params: {
        page: 1,
        pageSize: 10,
      },
      searchForm: {},
      tableData: [],
      total: 0,
      // 时间
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    this.pageQueryApply();
  },
  // 监听器
  watch: {
    params: {
      handler() {
        this.pageQueryApply();
      },
      deep: true,
    },
  },
  // 组件方法
  methods: {
    async changeStatus(id, status) {
      if (status === "通过") {
        let res = await checkPass(id);
      } else {
        let res = await checkNoPass(id);
      }
      this.pageQueryApply();
      this.$message({
        message: res.message,
        type: "success",
      });
    },
    moment,
    // 搜索
    toSearch() {
      this.pageQueryApply();
    },
    async pageQueryApply() {
      let temp = {
        ...this.params,
        ...this.search,
      };
      if (temp.time) {
        (temp.beginTime = temp.time[0]),
          (temp.endTime = temp.time[1]),
          delete temp.time;
      }

      for (let key in temp) {
        if (!temp[key]) {
          delete temp[key];
        }
      }

      let res = await pageQueryCertificationApply(temp);
      // console.log(res);
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
    // 处理分页函数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.params.pageSize = val;
      this.params.page = 1;
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.page = val;
    },
  },
  created() {
    this.pageQueryApply()
  },
};
</script>
<style lang="">
</style>